package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsTopic;
import com.qf.service.DtsGoodsService;
import com.qf.service.DtsTopicService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * projectName:workspace03
 * author:HardyWang
 * time:2021.11.30 19:22
 * description:
 */

@CrossOrigin("*")
@RestController
@RequestMapping("/admin/topic")
public class AdminTopicController {

    @Autowired
    DtsTopicService topicService;
    @Autowired
    DtsGoodsService goodsService;
    @RequestMapping("/list")
    public Object getLlist(
            @RequestParam(name = "page", required = false, defaultValue = "1") Integer page,
            @RequestParam(name = "limit", required = false, defaultValue = "20") Integer limit,
            String title ,
            String subtitle,
            @RequestParam(name = "sort", required = false, defaultValue = "add_time") String sort,
            @RequestParam(name = "order", required = false, defaultValue = "asc") String order){

        IPage<DtsTopic> ipage = topicService.queryPage(page, limit,title,subtitle, sort, order);

        Map<String,Object> data = new HashMap<>();
        data.put("total", ipage.getTotal() );
        data.put("items", ipage.getRecords());
        return ResponseUtil.ok(data);
    }

    @RequestMapping("update")
    public Object update(@RequestBody DtsTopic topic){
        return topicService.update(topic);
    }

    @RequestMapping("/create")
    public Object create(@RequestBody DtsTopic topic){
        return topicService.create(topic);
    }

    @RequestMapping("delete")
    public Object delete (@RequestBody DtsTopic topic){
        return topicService.delete(topic);
    }

}
